//package nbcp.base.config
//
//import org.slf4j.LoggerFactory
//import org.springframework.beans.factory.annotation.Value
//import org.springframework.context.annotation.Configuration
//import nbcp.base.extend.*
//import org.springframework.core.Ordered
//import org.springframework.core.annotation.Order
//import org.springframework.web.servlet.handler.HandlerInterceptorAdapter
//import nbcp.base.comm.JsonResult
//import nbcp.base.utils.HttpUtil
//import nbcp.base.utils.SpringUtil
//import nbcp.web.MyHttpRequestWrapper
//import nbcp.web.MyHttpResponseWrapper
//import java.nio.charset.Charset
//import javax.servlet.*
//import javax.servlet.http.HttpServletRequest
//import javax.servlet.http.HttpServletResponse
//
///**
// * Created by udi on 2017.3.11.
// */
//
//@Configuration
//class ProxyCorpFilter : Filter {
//
//    @Value("\${shop.corpApi.host:}")
//    var corpApiHost: String = ""
//
//    @Value("\${server.servlet.session.cookie.name:}")
//    var SessionKey: String = "";
//
//
//    override fun destroy() {
//    }
//
//    override fun doFilter(request: ServletRequest?, response: ServletResponse?, chain: FilterChain?) {
//        if (!(request is MyHttpRequestWrapper) || !(response is MyHttpResponseWrapper)) {
//            chain?.doFilter(request, response)
//            return
//        }
//
//        var myRequest = request!! as MyHttpRequestWrapper
//        var myResponse = response!! as MyHttpResponseWrapper
//
//        if (myRequest.requestURI.startsWith("/proxy/") == false ||
//                myRequest.method == "OPTIONS" ||
//                myRequest.method == "GET"
//        ) {
//            chain?.doFilter(myRequest, myResponse)
//            return
//        }
//
//        var url = corpApiHost + myRequest.requestURI.slice("/proxy".length) + "?" + myRequest.queryString.AsString()
//
//        var http = HttpUtil(url)
//        myRequest.headerNames.iterator().forEach { headerName ->
//            if (headerName.IsIn("Host", "Referer", "Pragma", "Cache-Control","Cookie")) {
//                return@forEach
//            }
//
////            if (headerName == "Cookie") {
////                var cookieValue = myRequest.getValue(headerName)
////                        .split(";")
////                        .ToProcMap({ it.split("=").map { it.trim() } }, { it[0].trim() }, { it[1].trim() })
////                        .filter { it.key == "lang" || it.key == SessionKey }
////                        .map { it.key + "=" + it.value }
////                        .joinToString("; ")
////
////                http.header.set(headerName, cookieValue)
////            }
//            http.header.set(headerName, myRequest.getValue(headerName))
//        }
//
//        http.header.set("proxy",myRequest.requestedSessionId)
//
//        try {
//            var responseBody = http.doPost(myRequest.body.toString(utf8))
//            myResponse.status = http.status
//            myResponse.writer.write(responseBody)
//        } catch (e: Exception) {
//            myResponse.status = 500;
//            var err = JsonResult()
//            err.msg = e.message ?: "网络调用错误"
//            myResponse.writer.write(err.ToJson())
//        }
//    }
//
//    override fun init(p0: FilterConfig?) {
//    }
//
//    companion object {
//        private val logger = LoggerFactory.getLogger(this::class.java.declaringClass)
//    }
//
//}